#ifndef _LINUX_HC_H
#define _LINUX_HC_H

#include <linux/timex.h>
#include <linux/workqueue.h>    /* for work queue */
#include <linux/slab.h>         /* for kmalloc() */

#define DEF_HC_THREAD_SLEEP_TIME	1000	/* 60000: 1 mins */
#define N_CLUSTER 2
#define hotness_t __u32
#define hotness_max __UINT32_MAX__
#define HOT_SECS 256 // 热度项粒度是多少个扇区，2048 是 1M
/* HOT_SECS		size	512G对应个数	总内存占用(个数*4B)
 * 2									2G
 * 256			128K					16M
 * 2048			1M		512K			2M
*/

#define MIN(a, b) ((a) < (b)) ? a : b
#define MAX(a, b) ((a) < (b)) ? b : a

struct dbcache_hc_kthread {
	struct task_struct *dbcache_hc_task;
	wait_queue_head_t hc_wait_queue_head;

	/* for hc sleep time */
	unsigned int sleep_time;
};

/* 数据库优化方案 */
struct hotness_cluster {
	hotness_t *hotness_array; // bucket的热度的数组
    __u64 hotness_nr;
    __u64 count;
	unsigned int centers[N_CLUSTER]; /* element 0 for backend device and element 1 for cache device. */
	bool centers_valid;
	struct dbcache_hc_kthread *hc_thread;
};

void hotness_ext(struct bio *bio, unsigned int *hotness_ext_start, unsigned int *hotness_ext_end);
int bch_hc_thread_start(struct cached_dev *dc);
void bch_hc_thread_stop(struct cached_dev *dc);
int hc_init(struct cached_dev *dc);
void hc_release(struct cached_dev *dc);

#endif
